package handler

import (
	"github.com/gin-gonic/gin"
	"internal/api/logic/login_register"
	"internal/api/types"
	"internal/util"
)

func UserLoginHandler(c *gin.Context) interface{} {
	resp := &types.LoginResp{}
	resp.Code = -1
	resp.AccessToken = ""
	resp.Msg = "server error"

	var req *types.LoginReq

	// 检查请求参数
	err := c.BindJSON(&req)
	if err != nil {
		resp.Msg = "http Params error"
		return resp
	}
	util.LogSrv.Debug("req=[%v]", req)
	// 业务逻辑
	err = login_register.AccountLogin(req, resp)
	if err != nil {
		resp.Msg = err.Error()
		return resp
	}
	resp.Code = 0
	resp.Msg = "success"
	return resp
}
